Python Lab


Python Lab: Systems of Equations

Linear equation: If $a$, $b$, and $c$ are real numbers, the graph of an equation of the form $$ax+by = c$$ is a straight line (if $a$ and $b$ are not both zero), so such an equation is called a linear equation in the variables $x$ and $y$.

Example: Solve \begin{cases} x+y=0\\ x-y=0,\\ \end{cases} Graphically.

matplotlib:

plotly:

Example: Solve \begin{cases} x+y+z=2\\ x+y+z=5 \end{cases}.

matplotlib:

plotly:

Solving linear system using back-substitution

Example: Solve the following linear system using back-substitution. \begin{equation*} \begin{cases} x_{1}+2\,x_{2}+3\,x_{3}=2\\ 4\,x_{1}-3\,x_{2}+x_{3}=-3\\ x_{2}-2\,x_{1}+3\,x_{3}=5 \end{cases} \end{equation*}

The corresponding augmented matrix is

In RREF:

Therefore, the solutions are:

To verify our answer, we can use linalg from Numpy. This requires converting the Matrix M into an array.